import 'package:flutter/services.dart';

import '../index.dart';

class CommonTextField extends BaseUpDownWidget {
  String? content;
  String? placeholder;
  int? maxLength;
  TextInputType? keyboardType;
  final ValueChanged<String>? onChanged;
  final TextEditingController _textEditingController = TextEditingController();

  CommonTextField(
      {Key? key,
      this.content,
      this.placeholder,
      this.onChanged,
      this.maxLength,
      this.keyboardType,
      required title,
      isHideDivide = false,
      isRequired = false})
      : super(
            key: key,
            title: title,
            isHideDivide: isHideDivide,
            isRequired: isRequired);

  @override
  Widget build(BuildContext context) {
    _textEditingController.text = content ?? "";
    setDownWidget(TextField(
      controller: _textEditingController,
      textAlign: TextAlign.left,
      style: Theme.of(context).textTheme.bodyLarge,
      maxLength: maxLength,
      maxLengthEnforcement: MaxLengthEnforcement.truncateAfterCompositionEnds,
      keyboardType: keyboardType,
      // maxLengthEnforcement: MaxLengthEnforcement.none,
      decoration: InputDecoration(
        border: InputBorder.none,
        hintText: placeholder ?? "请输入",
        // contentPadding: EdgeInsets.only(left: 2, top: 2),
        // filled: true,
        // border: OutlineInputBorder(
        //   borderRadius: BorderRadius.circular(4),
        // ),
      ),
      onChanged: (String value) {
        content = value;
        if (onChanged != null) {
          onChanged!(value);
        }
      },
    ));
    return super.build(context);
  }
}
